/*
 * Copyright 2004 original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.extremecomponents.table.tag;

import javax.servlet.http.HttpServletRequest;

import org.extremecomponents.table.bean.Table;
import org.extremecomponents.table.core.EccnTableConstants;
import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.tag.TableTag;
import org.extremecomponents.table.tag.TagUtils;

/**
 * @author Eccn-sunpauliz
 */
public class EccnTableTag extends TableTag
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 9206849882669772966L;
	/**
     * The location of pagination bar ,the value is "down" or "up".
     */
    private String paginationLocation;
    /**
     * Whether or not to show the rows displayed bar,the value is "true" or "false"
     */
    private String showRowsDisplayed;
    /**
     * Whether or not to show the goto pages bar,the value is "true" or "false"
     */
    private String showGotoPages;    
	
	/**
	 * @return Returns the paginationLocation.
	 */
	public String getPaginationLocation() {
		return paginationLocation;
	}

	/**
	 * @param paginationLocation The paginationLocation to set.
	 */
	public void setPaginationLocation(String paginationLocation) {
		this.paginationLocation = paginationLocation;
	}
	
    /**
	 * @return Returns the showGotoPage.
	 */
	public String getShowGotoPages() {
		return showGotoPages;
	}

	/**
	 * @param showGotoPage The showGotoPage to set.
	 */
	public void setShowGotoPages(String showGotoPages) {
		this.showGotoPages = showGotoPages;
	}

	/**
	 * @return Returns the showRowsDisplayed.
	 */
	public String getShowRowsDisplayed() {
		return showRowsDisplayed;
	}

	/**
	 * @param showRowsDisplayed The showRowsDisplayed to set.
	 */
	public void setShowRowsDisplayed(String showRowsDisplayed) {
		this.showRowsDisplayed = showRowsDisplayed;
	}

	public void addTableAttributes(TableModel model,Table table) {
		if (table.getAction() == null || "".equals(table.getAction())){
			HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
			table.setAction(request.getRequestURL().toString());
		}
		table.addAttribute(EccnTableConstants.PAGINATION_LOCATION, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.PAGINATION_LOCATION,
						this.paginationLocation, this, pageContext));
		table.addAttribute(EccnTableConstants.SHOW_GOTO_PAGES, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.SHOW_GOTO_PAGES,
						this.showGotoPages, this, pageContext));
		table.addAttribute(EccnTableConstants.SHOW_ROWS_DISPLAYED, TagUtils
				.evaluateExpressionAsString(EccnTableConstants.SHOW_ROWS_DISPLAYED,
						this.showRowsDisplayed, this, pageContext));
    }

    /**
	 * set the new attribuer to null
	 */
    public void release()
    {
        super.release();
        paginationLocation = null;
        showGotoPages = null;
        showRowsDisplayed = null;
    }
}
